//
//  RootTableViewController.m
//  Jiexi
//
//  Created by lanou3g on 15-4-6.
//  Copyright (c) 2015年 ncy. All rights reserved.
//

#import "RootTableViewController.h"
#import "NSObject+ResolveData.h"
#import "Model.h"
@interface RootTableViewController ()<UIWebViewDelegate>
@property(nonatomic,strong)NSMutableArray *DataArray;
@end

@implementation RootTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"太扯淡了吧,你这是新工程????");
    
    self.WebView = [[UIWebView alloc]initWithFrame:self.view.frame];
    NSLog(@"太扯淡了吧,你这是新工程????");
    NSLog(@"太扯淡了吧,你这是新工程????");
    NSLog(@"太扯淡了吧,你这dfdafdfd是新工程????");

    NSLog(@"nihao");
    NSLog(@"太扯淡了吧,你这是新工程????");

    NSLog(@"太扯淡了吧,你这是新工程????");

    NSLog(@"太扯淡了吧,你这是新工程????");

    
    NSString *string = [NSString stringWithFormat:@"http://star.zhuoyouapp.com/v1/contentServer/getContentById?contentId=455DE02A36ED4AB589CE1050E7CC73EA"];
//    NSURL *url = [NSURL URLWithString:string];
//    NSData *data = [NSData dataWithContentsOfURL:url];
    [NSObject resolveWithUrlStr:string method:@"GET" postBody:nil myBlock:^(id obj) {
       
        NSDictionary *dict = (NSDictionary *)obj;
        
        
        Model *model = [[Model alloc]init];
      
        self.WebView.delegate = self;
        for (NSDictionary *Dict in dict[@"entity"]) {
            [model setValuesForKeysWithDictionary:Dict];
            
            
           
            
            
        }
        NSLog(@"%@",model.content);
        NSString * path = [[NSBundle mainBundle] pathForResource:@"html" ofType:@"txt"];
        
        NSMutableString * str = [NSMutableString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
        
        NSString * cssPath = [[NSBundle mainBundle] pathForResource:@"htmlCSS" ofType:@"css"];
        
        NSRange rangeOfCSSPath = [str rangeOfString:@"#CSSPath#"];
        //    NSLog(@"%@",NSStringFromRange(rangeOfCSSPath));
        [str replaceCharactersInRange:rangeOfCSSPath withString:cssPath];
        NSRange sourceRange = [str rangeOfString:@"#source#"];
        if (model.content)
        {
            [str replaceCharactersInRange:sourceRange withString:model.content];
        }
        [self.WebView loadHTMLString:str baseURL:nil];
        [self.view addSubview:self.WebView];
        
    }];
    
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
